<template>
	<view>
		<view class="cash_in_yzm"><view class="yzm_text">手机号：</view><input class="yzm" type="text" name="yzm" @input="inphone" placeholder="请输入手机号" />
		</view>
		<view class="cash_in_yzm"><view class="yzm_text">验证码:</view><input class="yzm" type="text" name="yzm" @input="codenum" placeholder="手机验证码" />
		<view v-if="show_yzm">
			<view class="yzm_btn" @tap="yzm">获取验证码</view>
		</view>
		<view v-else>
			<view class="yzm_btn2">剩余{{seconde}}s</view>
		</view>
		</view>
		<view class="btn"><button type="primary" @tap="bind">绑定</button></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id:'',
				code_num:'',
				phone:'',
				show_yzm:true,
				seconde:'60',
			}
		},
		onLoad(option) {
			const id=option.id
			this.id=id
			console.log(id)
			console.log("用户小程序id",this.$store.state.token)
			uni.request({
				url:'http://tuiguang.yiyunoto.com/api/index/index',
				header:{authtoken:this.$store.state.token},
				method:'POST',  
				success:(res)=>{
					console.log('12',res)
					if(res.data.msg=="该账号在其他设备登录"){
						uni.showToast({
							title:"该账号在其他设备登录，请从新登陆",
							icon:'none'
						})
						return;
					}else{
						console.log('12')
						uni.switchTab({
							url:'../index/index'
						})
					}			
				},
				fail:(res)=>{
					console.log("请求失败",res)
				}
			})
			
		},
		
		methods: {
			inphone(e){
				console.log(e.detail.value)
				this.phone=e.detail.value
			},
			codenum(e){
				console.log(e.detail.value)
				this.code_num=e.detail.value
			},
			yzm:function(){
				console.log("获取验证码",this.tel)
					uni.request({
							url: 'http://tuiguang.yiyunoto.com/api/login/smsSend',
							method:'POST',
							// header:{authtoken:this.$store.state.token},
							data:{
								phone:this.phone,
							},
								success: (res) => {
									this.$api.msg(res.data.msg);
									if(res.data.msg=="短信验证码发送成功"){
									this.show_yzm=false,
									setInterval(()=>{
										--this.seconde
									},1000)
									setTimeout(()=>{
										this.show_yzm=true,
										this.seconde=60
										},
										60000
									)}
							console.log("ya",res.data.msg)							// console.log(res.data.data);
							}
						});
				},
			
			bind(){
				uni.request({
					url:'http://tuiguang.yiyunoto.com/api/login/bindPhone',
					header:{authtoken:this.id},
					data:{
						// accesstoken:this.id,
						code:this.code_num,
						phone:this.phone
					},
					method:'POST',  
					success:(res)=>{  
						console.log("小程序绑定",res)
						if(res.data.code==1){
							// uni.navigateTo({
							// 	url:'../Binding_phone/Binding_phone?id='+res.data.data.accesstoken
							// })
						}
					},
					fail:(res)=>{
						console.log("请求失败",res)
					}
				})
			}
		}
	}
</script>

<style>
.cash_in_yzm{
		width: 100%;
		height: 100upx;
		padding: 30upx 30upx;
		margin-top: 18upx;
		box-shadow: 0upx 5upx 20upx rgba(0, 0, 0, 0.1);
		box-sizing: border-box;
		background: #FFFFFF;
	}
	.yzm_text{
		width:25%;
		float: left;
		
	}
	.yzm {
		width:50%;
		float: left;
	}
	.yzm_btn {
		width: 25%;
		font-size: 26upx;
		text-align: right;
		float: right;
		color: blue;
	
	}
	.yzm_btn2{
		width:25%;
		font-size: 26upx;
		text-align: right;
		float: right;
		color: #DBDADA;
	}
.btn{
	width: 50%;
	margin: 50upx auto;
	border-radius: 20upx;
	background: #007AFF;
}
</style>
